<?php

class Lienket extends CI_Controller {
    
    function __construct() {
        parent::__construct();
		$this->load->library('form_validation');		
		$this->load->helper(array('form','url','codegen_helper'));
		$this->load->model('codegen_model','',TRUE);
	}	
	
	function index(){
		$this->manage();
	}

	function manage(){
        $this->load->library('table');
        $this->load->library('pagination');
        
        //paging
        $config['base_url'] = base_url().'index.php/lienket/manage/';
        $config['total_rows'] = $this->codegen_model->count('lienket');
        $config['per_page'] = 10;	
        $this->pagination->initialize($config); 	
        $this->data['results'] = $this->codegen_model->get('lienket','idWebLink,Ten,url','',$config['per_page'],$this->uri->segment(3));
       
        $this->load->view('admin/lienket/lienket_list', $this->data); 
       //$this->template->load('content', 'lienket_list', $this->data); // if have template library , http://maestric.com/doc/php/codeigniter_template
		
    }
	
    function add(){        
        $this->load->library('form_validation');    
		$this->data['custom_error'] = '';
		
        if ($this->form_validation->run('lienket') == false)
        {
             $this->data['custom_error'] = (validation_errors() ? '<div class="form_error">'.validation_errors().'</div>' : false);

        } else
        {                            
            $data = array(
                    'Ten' => set_value('Ten'),
                    'url' =>  $this->input->post('url')
            );
           
            if ($this->codegen_model->add('lienket',$data) == TRUE)
            {
                    redirect(base_url().'lienket/manage/');
            }
            else
            {
                    $this->data['custom_error'] = '<div class="form_error"><p>An Error Occured.</p></div>';

            }
    }		   
    $this->load->view('admin/lienket/lienket_add', $this->data);   
    }	
    
    function edit(){        
        $this->load->library('form_validation');    
        $this->data['custom_error'] = '';
		
        if ($this->form_validation->run('lienket') == false)
        {
             $this->data['custom_error'] = (validation_errors() ? '<div class="form_error">'.validation_errors().'</div>' : false);

        } else
        {                            
            $data = array(
                    'Ten' => $this->input->post('Ten'),
					'url' => $this->input->post('url')
            );
           
			if ($this->codegen_model->edit('lienket',$data,'idWebLink',$this->input->post('idWebLink')) == TRUE)
			{
				redirect(base_url().'index.php/lienket/manage/');
			}
			else
			{
				$this->data['custom_error'] = '<div class="form_error"><p>An Error Occured</p></div>';

			}
		}

		$this->data['result'] = $this->codegen_model->get('lienket','idWebLink,Ten,url','idWebLink = '.$this->uri->segment(3),NULL,NULL,true);
		
		$this->load->view('admin/lienket/lienket_edit', $this->data);		
        //$this->template->load('content', 'lienket_edit', $this->data);
    }
	
    function delete(){
            $ID =  $this->uri->segment(3);
            $this->codegen_model->delete('lienket','idWebLink',$ID);             
            redirect(base_url().'index.php/lienket/manage/');
    }
}

/* End of file lienket.php */
/* Location: ./system/application/controllers/lienket.php */